//
//  LocationButton.m
//  SheShiDu
//
//  Created by 单剑秋 on 16/6/20.
//  Copyright © 2016年 单剑秋. All rights reserved.
//

#import "LocationButton.h"

@implementation LocationButton

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        self.titleLabel.font = [UIFont systemFontOfSize:15];
        self.titleLabel.textAlignment = NSTextAlignmentLeft;
        
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    if (self.titleLabel.frame.origin.x != 0) {
        
        if (self.imageView.frame.origin.x > self.titleLabel.frame.origin.x) {
            // 交换图片和文字的位置
            CGRect tempImageViewRect = self.imageView.frame;
            tempImageViewRect.origin.x = 10;
            self.imageView.frame = tempImageViewRect;
            
            CGRect tempTitleLabelRect = self.titleLabel.frame;
            tempTitleLabelRect.origin.x = self.imageView.frame.origin.x + self.imageView.frame.size.width + 5;
            self.titleLabel.frame = tempTitleLabelRect;
        }
        
    }
    
    
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
